import { useJumpPage } from "./open";

export const useNavigator = () => {
  const memberPrefix = "/pages/member/";
  const payPrefix = "/pages/pay/";
  const [to, store] = useJumpPage();

  const toMember = {
    toAddress: () => to`${memberPrefix + "address/address"}`,
    toHelp: () => uni.navigateTo({ url: `${memberPrefix + "help/help"}` }),
    toSingle: (page) => uni.navigateTo({ url: `${memberPrefix + "help/single?current=" + page}` }),
    toMessage: () => to`${memberPrefix + "message/message"}`,
    toFuture: () => to`${memberPrefix + "future/future"}`,
    toFavorite: () => to`${memberPrefix + "favorite/favorite"}`,
    toMemberInfo: () => to`${memberPrefix + "info/info"}`,
    toSetting: () => to`${memberPrefix + "setting/setting"}`,
    toChat: () => uni.navigateTo({ url: `${"/pages/chat/chat"}` }),
    toSettingEdit: () => to`${memberPrefix + "setting/edit"}`,
  };

  const toOrder = {
    /**
     * 跳转到物流页面
     * @param {Number} num 物流单号
     * @param {String} name 物流公司名称
     * @returns
     */
    toTrack: (num, name) => to`${"/pages/order/logistics?id=" + num + "&name=" + name}`,
    toQuotes: () => to`${"/pages/order/quotes"}`,
  };

  const toPay = {
    toPay: (orderno) => to`${payPrefix + "pay?orderno=" + orderno}`,
  };

  return {
    store,
    ...toOrder,
    ...toMember,
    ...toPay,
  };
};
